package com.hqyj.controller;

import com.hqyj.pojo.MakeApply;
import com.hqyj.pojo.customerInfo;
import com.hqyj.service.service.InsertData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/apply")
// 申请服务的类
public class applyController {
    @Autowired()
    InsertData insertData;

    @RequestMapping("/applyList")
    @ResponseBody

    public List<MakeApply> getApplyList(){
        List<MakeApply> makeApplies = new ArrayList<>();
        makeApplies = insertData.findFromApplyTable();
        return makeApplies;
    }


    // 后台服务申请 点击处理后的逻辑1.将申请查询出来
    @ResponseBody
    @RequestMapping("/selectApply")
    public List<MakeApply> selectApply(String userName){
        System.out.println(userName);
        List<MakeApply> findMake = new ArrayList<>();
        findMake = insertData.findByName(userName);
        return findMake;
    }
    // 后台服务申请 点击处理提交后的逻辑2. 将记录插入数据库
    // 后台服务申请 点击处理提交后的逻辑2. 将记录插入数据库
    @ResponseBody
    @RequestMapping("/insertApply")
    public HashMap<String,Object> insertApply(String customerId,String userName, String dealCalender, String predictCost, String serviceTime, String Dealed){
        HashMap<String,Object> map = new HashMap<String,Object>();
        String info = insertData.updateApply(customerId, userName, dealCalender, predictCost, serviceTime, Dealed);
        map.put("status",info);
        return map;
    }




    //查询服务记录
    @ResponseBody
    @RequestMapping("/serviceList")
    public Map<String,Object> serviceList(){
        Map<String,Object> map = new HashMap<>();
        List<MakeApply> findServiceList = new ArrayList<>();
        findServiceList = insertData.findSerList();
        map.put("code",0);
        map.put("msg","");
        map.put("count",1000);
        map.put("data",findServiceList);
        return map;
    }


    //修改remark
    @ResponseBody
    @RequestMapping("/updateRemark")
    public HashMap<String,Object> updateRemark(String remark, String Id){
        HashMap<String,Object> map = new HashMap<String,Object>();
        String info = insertData.updateRemark(remark, Id);
        System.out.println("**************************************");
        System.out.println(info);
        System.out.println("**************************************");
        map.put("info",info);
        return map;
    }


    //根据用户名，获取用户的地址和邮箱
    @ResponseBody
    @RequestMapping("/askEmailAddress")
    public HashMap<String,Object> askEmailAddress(String customerName){
        HashMap<String,Object> map = new HashMap<String,Object>();
        List<customerInfo> customerInfos = new ArrayList<>();
        customerInfos = insertData.askAddByName(customerName);
        map.put("Listinfo",customerInfos);
        return map;
    }


    //根据ID将数据回显
    @ResponseBody
    @RequestMapping("/selectById")
    public List<MakeApply> selectById(String Id){

        List<MakeApply> Ids = new ArrayList<>();
        Ids = insertData.findById(Id);
        return Ids;
    }

}
